{  Statement: http://acmp.ru/?main=task&id_task=131
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i,n,k,s,mx,ans:longint;    

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
mx := 0;
ans := -1;
for i:=1 to n do begin
    read(k,s);
    if (s = 1) and (k > mx) then begin
        mx := k;
        ans := i;
    end;
end;
write(ans);
end.